home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / c / flash-0.4.3.lha / flash-0.4.3 / Lib / flash.cc < prev    next >
C/C++ Source or Header  |  1999-02-21  |  5KB  |  232 lines

  1. /////////////////////////////////////////////////////////////
  2. // Flash Plugin and Player
  3. // Copyright (C) 1998,1999 Olivier Debon
  4. // 
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9. // 
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. // 
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. // 
  19. ///////////////////////////////////////////////////////////////
  20. //  Author : Olivier Debon  <odebon@club-internet.fr>
  21. //  
  22.  
  23. #include "script.h"
  24. #include "graphic.h"
  25. #include "flash.h"
  26. #include "sound.h"
  27.  
  28. static char *rcsid = "$Id: flash.cc,v 1.19 1999/01/31 20:18:39 olivier Exp $";
  29.  
  30. struct PrvFlashHandle {
  31.     CInputScript * pInputScript;
  32.     long msPerFrame;
  33.     GraphicDevice *gd;
  34.     SoundMixer    *sm;
  35.  
  36.     PrvFlashHandle() {
  37.         pInputScript = new CInputScript;
  38.         gd = 0;
  39.         sm = 0;
  40.     };
  41.  
  42.     ~PrvFlashHandle() {
  43.         delete pInputScript;
  44.         delete gd;
  45.         delete sm;
  46.     };
  47. };
  48.  
  49. // Interface with standard C
  50. extern "C" {
  51.  
  52. FlashHandle
  53. FlashParse(char *data, long size)
  54. {
  55.     PrvFlashHandle *fh;
  56.  
  57.     fh = new PrvFlashHandle;
  58.  
  59.     if (fh->pInputScript->ParseData(data, size)) {
  60.         fh->msPerFrame = 1000/fh->pInputScript->frameRate;
  61.         fh->pInputScript->program->rewindMovie();
  62.  
  63.         return (FlashHandle)fh;
  64.     }
  65.  
  66.     delete fh;
  67.  
  68.     return 0;
  69. }
  70.  
  71. void
  72. FlashGetInfo(FlashHandle flashHandle, struct FlashInfo *fi)
  73. {
  74.     PrvFlashHandle *fh;
  75.  
  76.     fh = (PrvFlashHandle *)flashHandle;
  77.  
  78.     fi->version = fh->pInputScript->m_fileVersion;
  79.     fi->frameRate = fh->pInputScript->frameRate;
  80.     fi->frameCount = fh->pInputScript->frameCount;
  81.     fi->frameWidth = fh->pInputScript->frameRect.xmax - fh->pInputScript->frameRect.xmin;
  82.     fi->frameHeight = fh->pInputScript->frameRect.ymax - fh->pInputScript->frameRect.ymin;
  83. }
  84.  
  85. long
  86. FlashGraphicInit(FlashHandle flashHandle,Display *dpy, Window target)
  87. {
  88.     PrvFlashHandle *fh;
  89.  
  90.     fh = (PrvFlashHandle *)flashHandle;
  91.  
  92.     fh->gd = new GraphicDevice(dpy, target);
  93.  
  94.     fh->gd->setMovieDimension(fh->pInputScript->frameRect.xmax - fh->pInputScript->frameRect.xmin,
  95.                   fh->pInputScript->frameRect.ymax - fh->pInputScript->frameRect.ymin);
  96.  
  97.     return 1;    // Ok
  98. }
  99.  
  100. void
  101. FlashSoundInit(FlashHandle flashHandle, char *device)
  102. {
  103.     PrvFlashHandle *fh;
  104.  
  105.     fh = (PrvFlashHandle *)flashHandle;
  106.  
  107.     fh->sm = new SoundMixer(device);
  108. }
  109.  
  110. void
  111. FlashZoom(FlashHandle flashHandle, int zoom)
  112. {
  113.     PrvFlashHandle *fh;
  114.  
  115.     fh = (PrvFlashHandle *)flashHandle;
  116.  
  117.     fh->gd->setMovieZoom(zoom);
  118. }
  119.  
  120. void
  121. FlashOffset(FlashHandle flashHandle, int x, int y)
  122. {
  123.     PrvFlashHandle *fh;
  124.  
  125.     fh = (PrvFlashHandle *)flashHandle;
  126.  
  127.     fh->gd->setMovieOffset(x,y);
  128. }
  129.  
  130. long
  131. FlashExec(FlashHandle flashHandle,long flag, XEvent *event, struct timeval *wakeDate)
  132. {
  133.     PrvFlashHandle *fh;
  134.     long wakeUp = 0;
  135.     long geturl;
  136.  
  137.     fh = (PrvFlashHandle *)flashHandle;
  138.  
  139.     switch (flag & FLASH_CMD_MASK) {
  140.         case FLASH_STOP:
  141.             fh->pInputScript->program->pauseMovie();
  142.             wakeUp = 0;
  143.             break;
  144.         case FLASH_CONT:
  145.             fh->pInputScript->program->continueMovie();
  146.             wakeUp = 1;
  147.             break;
  148.         case FLASH_REWIND:
  149.             fh->pInputScript->program->rewindMovie();
  150.             wakeUp = 0;
  151.             break;
  152.         case FLASH_STEP:
  153.             fh->pInputScript->program->nextStepMovie();
  154.             wakeUp = 0;
  155.             break;
  156.     }
  157.  
  158.     if (flag & FLASH_WAKEUP) {
  159.         // Compute next wakeup time
  160.         gettimeofday(wakeDate,0);
  161.         wakeDate->tv_usec += fh->msPerFrame*1000;
  162.         if (wakeDate->tv_usec > 1000000) {
  163.             wakeDate->tv_usec -= 1000000;
  164.             wakeDate->tv_sec++;
  165.         }
  166.  
  167.         // Play frame
  168.         wakeUp = fh->pInputScript->program->processMovie(fh->gd, fh->sm);
  169.     }
  170.  
  171.     if (flag & FLASH_EVENT) {
  172.         FlashEvent fe;
  173.  
  174.         // X to Flash event structure conversion
  175.         switch (event->type) {
  176.             case ButtonPress:
  177.                 fe.type = FeButtonPress;
  178.                 break;
  179.             case ButtonRelease:
  180.                 fe.type = FeButtonRelease;
  181.                 break;
  182.             case MotionNotify:
  183.                 fe.type = FeMouseMove;
  184.                 fe.x = event->xmotion.x;
  185.                 fe.y = event->xmotion.y;
  186.                 break;
  187.             case Expose:
  188.                 fe.type = FeRefresh;
  189.                 break;
  190.         }
  191.  
  192.         if (fh->pInputScript->program->handleEvent(fh->gd, fh->sm, &fe)) {
  193.             gettimeofday(wakeDate,0);    // Wake up at once !!!
  194.             wakeUp = 1;
  195.         }
  196.     }
  197.  
  198.     return wakeUp;
  199. }
  200.  
  201. void
  202. FlashSetGetUrlMethod(FlashHandle flashHandle, void (*getUrl)(char *, char *, void *), void *clientData)
  203. {
  204.     PrvFlashHandle *fh;
  205.  
  206.     fh = (PrvFlashHandle *)flashHandle;
  207.  
  208.     fh->pInputScript->program->setGetUrlMethod( getUrl, clientData );
  209. }
  210.  
  211. void
  212. FlashClose(FlashHandle flashHandle)
  213. {
  214.     PrvFlashHandle *fh;
  215.  
  216.     fh = (PrvFlashHandle *)flashHandle;
  217.  
  218.     delete fh;
  219. }
  220.  
  221. void
  222. FlashSettings(FlashHandle flashHandle, long settings)
  223. {
  224.     PrvFlashHandle *fh;
  225.  
  226.     fh = (PrvFlashHandle *)flashHandle;
  227.  
  228.     fh->pInputScript->program->modifySettings( settings );
  229. }
  230.  
  231. }; /* end of extern C */
  232.